<!-- 会员福利模块 -->
<template>
	<view class="container">
		<view class="title">邮惠福利</view>
		<view class="tabs">
			<view class="tabs-item" :class="{ 'is-activate': item.isActivate }" v-for="(item,index) in TABS" :key="item.name" @click="onTabChange(index)">
				{{ item.name }}
			</view>
		</view>
		<view v-if="props.awards?.length" class="list">
			<!-- 卡券组件 -->
			<gzCouponCard v-for="(_,i) in props.awards" :key="i" :couponInfo="_" @clickHandle="clickHandle"/>
		</view>
		<image v-else class="no-coupon-img" src="https://jdyd-marketing-public.oss-cn-hangzhou.aliyuncs.com/yx/c52578d2-81fd-4b3d-b4ed-39c723a5757a.png"></image>
	</view>
</template>

<script setup>
	import { ref, reactive, getCurrentInstance, defineExpose, watch } from 'vue'
	
	const emits = defineEmits(['clickHandle','tabsChange','update:tabIndex'])
	
	const props = defineProps({
		awards: {
			type: Array,
			default: []
		},
		tabIndex: {
			type: Number,
			default: 0
		}
	})
	
	// 监听tabIndex
	watch(() => props.tabIndex,() => {
		TABS.value.forEach((item,index) => {
			if(props.tabIndex === index){
				item.isActivate = true
			}else{
				item.isActivate = false
			}
		})
	})
	
	// tabs
	const TABS = ref([
		{ name: '全区会员福利', isActivate: true },
		{ name: '区域专享', isActivate: false },
		{ name: '商家券', isActivate: false }
	])
	// tabs切换事件
	function onTabChange(currentIndex){
		if(props.tabIndex === currentIndex) return	// 避免重复点击切换
		// 更新tabIndex
		emits('update:tabIndex',currentIndex)
		// 通知父组件拉取当前类别卡券列表
		uni.showLoading({ title: '加载中...', mask: true })
		emits('tabsChange')
	}
	
	function clickHandle(e){
		emits('clickHandle',e)
	}
</script>

<style lang="less" scoped>
	.container{
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 24rpx;
		padding: 44rpx 32rpx;
		.tabs{
			display: flex;
			background-color: #EEEEEE;
			border-radius: 24rpx;
			color: #999999;
			font-size: 28rpx;
			align-items: center;
			justify-content: space-between;
			.tabs-item{
				width: 33%;
				padding: 20rpx 22rpx;
				text-align: center;
				border-radius: 24rpx;
				&.is-activate{
					background-color: #EAFAF4;
					color: #24C789;
				}
			}
		}
		.title{
			font-weight: bold;
			font-size: 34rpx;
			margin-bottom: 44rpx;
		}
		.list{
			width: 100%;
			display: flex;
			flex-direction: column;
			gap: 24rpx;
			margin-top: 24rpx;
		}
		.no-coupon-img{
			width: 480rpx;
			height: 480rpx;
			display: block;
			margin: 0 auto;
		}
	}
</style>